package study4;
import java.util.Random;
import java.util.Scanner;
public class 简单模拟微信抢红包小程序 {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        System.out.println("请您输入总金额:");
        double sum=sc.nextDouble();
        System.out.println("请输入红包个数:");
        int people=sc.nextInt();
        start(sum,people);
    }
    private static void start(double sum, int people) {
        double min=0.01;
        Random random=new Random();
        for(int i=1;i<people;i++)
        {
            double max=sum-min*(people-i);
            double bound=max-min;
            double safe=(double)random.nextInt((int) (bound*100))/100;
            double money=safe+min;
            sum=sum-money;
            System.out.println("第"+i+"个红包:"+String.format("%.2f", money)+"元");
        }
        System.out.println("第"+people+"个红包:"+String.format("%.2f",sum)+"元");
    }
}


